﻿
// GraphicsView.cpp: CGraphicsView 类的实现

#include<math.h>
#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "Graphics.h"
#endif

#include "GraphicsDoc.h"
#include "GraphicsView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif



// CGraphicsView

IMPLEMENT_DYNCREATE(CGraphicsView, CView)

BEGIN_MESSAGE_MAP(CGraphicsView, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CGraphicsView::OnFilePrintPreview)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
END_MESSAGE_MAP()

// CGraphicsView 构造/析构

CGraphicsView::CGraphicsView() noexcept
{
	// TODO: 在此处添加构造代码

}

CGraphicsView::~CGraphicsView()
{
}

BOOL CGraphicsView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// CGraphicsView 绘图

void CGraphicsView::OnDraw(CDC* pDC)
{
	CGraphicsDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: 在此处为本机数据添加绘制代码
	int i;
	pDC->SetTextColor(RGB(255, 0, 255)); 		// 设备文本的前景色
	pDC->TextOut(20, 20, _T("Point"));		// 输出Point提示
	pDC->SetPixel(100, 20, RGB(255, 0, 0));	// 以不同的颜色画点
	pDC->SetPixel(110, 20, RGB(0, 255, 0));
	pDC->SetPixel(120, 20, RGB(0, 255, 255));
	pDC->SetPixel(120, 20, RGB(255, 255, 0));
	pDC->SetPixel(140, 20, RGB(255, 0, 255));
	pDC->SetPixel(150, 20, RGB(0, 255, 255));
	pDC->SetPixel(160, 20, RGB(0, 0, 0));
	// 绘制直线
	pDC->TextOut(20, 60, _T("Line"));
	pDC->MoveTo(20, 90);
	pDC->LineTo(160, 90);
	pDC->LineTo(130, 80);
	// 绘制折线
	POINT polyline[4] = { {50,220},{20,170},{70,200},{20,220} };
	pDC->Polyline(polyline, 4);
	// 绘制Bezier曲线
	POINT polyBezier[4] = { {20,310},{60,240},{120,300},{160,330} };
	pDC->PolyBezier(polyBezier, 4);
	// 绘制圆
	for (i = 4; i < 6; i++)
	{
		pDC->Arc(260 - 5 * i, 70 - 5 * i, 260 + 5 * i, 70 + 5 * i, 260 + 5 * i, 70, 260 + 5 * i, 70);
	}
	// 绘制圆弧
	for (i = 5; i < 7; i++)
	{
		pDC->Arc(210 - 10 * i, 70 - 10 * i, 210 + 10 * i, 70 + 10 * i,
			(int)210 + 10 * i * cos(60 * 3.1415926 / 180),
			(int)70 + 10 * i * sin(60 * 3.1415926 / 180),
			(int)210 + 10 * i * cos(60 * 3.1415926 / 180),
			(int)70 - 10 * i * sin(60 * 3.1415926 / 180));

		pDC->Arc(240 - 10 * i, 70 - 10 * i, 240 + 10 * i, 70 + 10 * i,
			(int)240 - 10 * i * cos(60 * 3.1415926 / 180),
			(int)70 - 10 * i * sin(60 * 3.1415926 / 180),
			(int)240 - 10 * i * cos(60 * 3.1415926 / 180),
			(int)70 + 10 * i * sin(60 * 3.1415926 / 180));
	}
	// 绘制椭圆
	pDC->Ellipse(200, 160, 280, 200);
	// 绘制矩形和圆角矩形
	pDC->Rectangle(190, 270, 250, 310);
	pDC->RoundRect(265, 270, 330, 310, 30, 20);
	// 绘制扇形
	pDC->Pie(360 - 70, 70 - 80, 360 + 80, 70 + 80,
		(int)360 + 70 * cos(60 * 3.1415926 / 180),
		(int)70 + 70 * sin(60 * 3.1415926 / 180),
		(int)360 + 70 * cos(30 * 3.1415926 / 180),
		(int)70 - 70 * sin(30 * 3.1415926 / 180));
	// 绘制三角形
	POINT polygon[3] = { {300,160},{400,220},{310,210} };
	pDC->Polygon(polygon, 3);
}


// CGraphicsView 打印


void CGraphicsView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
	AFXPrintPreview(this);
#endif
}

BOOL CGraphicsView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CGraphicsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CGraphicsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}

void CGraphicsView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CGraphicsView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// CGraphicsView 诊断

#ifdef _DEBUG
void CGraphicsView::AssertValid() const
{
	CView::AssertValid();
}

void CGraphicsView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CGraphicsDoc* CGraphicsView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGraphicsDoc)));
	return (CGraphicsDoc*)m_pDocument;
}
#endif //_DEBUG


// CGraphicsView 消息处理程序
